package oct2013.linkednode;

public class BalancedBinaryTree {

	public boolean isBalanced(TreeNode root) {
		balanced = true;
		height(root);
		return balanced;
	}

	boolean balanced;

	int height(TreeNode root) {
		if (root == null)
			return 0;
		int lh = height(root.left);
		int rh = height(root.right);
		if (Math.abs(lh - rh) > 1) {
			balanced = false;
		}
		return Math.max(lh, rh) + 1;
	}

}
